home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / client / btree / ParentStack.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  3.0 KB  |  126 lines

  1. /*
  2.  * $RCSfile: ParentStack.C,v $
  3.  * $Revision: 1.1.1.1 $
  4.  * $Date: 1996/05/04 21:55:16 $
  5.  */
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "BTREEPAGE.h"
  38. #include "ParentStack.h"
  39.  
  40.  
  41.  
  42. //
  43. //    Class        : ParentStack
  44. //    Method        : Destructor
  45. //    Description    : Unfix every page in the stack. If the page is not leaf, 
  46. //                  unlock it, too.
  47. //
  48. ParentStack::~ParentStack()
  49. {
  50.     while (cnt-- > 0)  {
  51.         if ((GROUPLINK*)descPtr[cnt])  {
  52.             BTREEPAGE* bp = descPtr[cnt];
  53.             if (bp->IsNode())
  54.                 descPtr[cnt].UnfixUnlock();
  55.             else
  56.                 descPtr[cnt].Unfix();
  57.             }
  58.         }
  59. }
  60.  
  61.  
  62.  
  63. //
  64. //    Class        : ParentStack
  65. //    Method        : void DiscardTop()
  66. //    Description    : Pop the top entry int he stack and unfix it. If it is
  67. //                  not a leaf, unlock it as well.
  68. //
  69. void ParentStack::DiscardTop()
  70. {
  71.     PageDesc pd = Pop();
  72.     BTREEPAGE* bp = pd;
  73.  
  74.     if (bp)  {
  75.         if (bp->IsNode())
  76.             pd.UnfixUnlock();
  77.         else
  78.             pd.Unfix();
  79.         }
  80. }
  81.  
  82.  
  83.  
  84. //
  85. //    Class        : ParentStack
  86. //    Method        : int ReadNPush(PID& const pid, LOCKMODE lockMode)
  87. //    Description    : Read page 'pid' with 'lockMode', and push it onto the stack.
  88. //
  89. int ParentStack::ReadNPush(const PID& pid, LOCKMODE lockMode)
  90. {
  91.     PageDesc pd;
  92.  
  93.     if (pd.Read(bufGroup, pid, lockMode))
  94.         return esmFAILURE;
  95.  
  96.     Push(pd);
  97.  
  98.     return esmNOERROR;
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. //
  107. //    Class        : ParentStack
  108. //    Method        : void Print()
  109. //    Description    : Prints the stack for debugging purposes
  110. //
  111. void ParentStack::Print() 
  112.     printf("ParentStack: \n"); 
  113.     for (int i = 0; i < cnt; i++)  {
  114.         BTREEPAGE* bt = descPtr[i];
  115.         if (bt == 0) {
  116.             printf("\tdescPtr[%d] is released\n", i);
  117.             continue;
  118.             }
  119.         printf("\tdescPtr[%d] = page %d, level %d, freeSpace %d\n", i, 
  120.                             bt->SelfID().page, bt->Level(),
  121.                             bt->FreeSpace());
  122.         }
  123. }
  124.  
  125.